if __name__ == '__main__':
    from PIL import Image
    import numpy as np
    import sys
    import argparse

    parser = argparse.ArgumentParser(description='show npy image')
    parser.add_argument('npy_path', default=None, metavar='NPY_PATH', type=str,
                        help='Path to the npy file')
    parser.add_argument('img_path', default='-', metavar='IMG_PATH', type=str,
                        help='Path to the image file, or - output as [npy_path].jpg')
    args = parser.parse_args()

    im = np.load(args.npy_path)
    if im.dtype == "float64":
        scale = 0.98
        im = (im - scale) * (255.0 / (1.0 - scale))
        img = Image.fromarray(im)
        img = img.convert('RGB')
    else:
        img = Image.fromarray(im)
    
    if args.img_path == '-':
        img.save(args.npy_path + '.jpg')
    else:
        img.save(args.img_path)
